package com.harmontronics.hanma.paas.paas.domain.app.repository.persistence;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HmDictionaryMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HmDictionaryPO;
import com.harmontronics.hanma.paas.paas.utils.EscapeUtil;
import com.harmontronics.hanma.paas.paas.utils.StringUtil;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;


@Repository("hmDictionaryRepository")
public class HmDictionaryRepository extends ServiceImpl<HmDictionaryMapper, HmDictionaryPO> {

    public IPage<HmDictionaryPO> selectPage(Wrapper<HmDictionaryPO> queryWrapper, Page<HmDictionaryPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }

    public List<HmDictionaryPO> digestList(String type,String keyword,Integer limit){
       /* LambdaQueryWrapper<HmDictionaryPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtil.isNotBlank(type),HmDictionaryPO::getType,type);
//        queryWrapper.like(StringUtil.isNotBlank(keyword),HmDictionaryPO::getOptionName, EscapeUtil.escapeChar(keyword));
        queryWrapper.last(limit != null,"LIMIT "+limit);
        queryWrapper.orderByAsc(HmDictionaryPO::getCreateDate);*/
        QueryWrapper<HmDictionaryPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtil.isNotBlank(type),"type",type);
        queryWrapper.like(StringUtil.isNotBlank(keyword),"option_name",EscapeUtil.escapeChar(keyword));
        queryWrapper.last(limit != null,"LIMIT "+limit);
        queryWrapper.orderByAsc("create_date");
        return baseMapper.selectList(queryWrapper);
    }

}